package online.longzipeng.mywebdemo.service.impl;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import online.longzipeng.mywebdemo.entity.User;
import online.longzipeng.mywebdemo.mapper.UserMapper;
import online.longzipeng.mywebdemo.pojo.dto.UserSearchDTO;
import online.longzipeng.mywebdemo.service.UserService;
import org.springframework.stereotype.Service;

/**
 * @Author: lzp
 * @description:
 * @Date: 2022/12/6
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

	@Override
	public Page<User> page(UserSearchDTO param) {
		Page<User> page = new Page<>(param.getCurrent(), param.getSize());
		return baseMapper.selectPage(page, Wrappers.<User>lambdaQuery()
				.likeRight(StrUtil.isNotBlank(param.getUsername()), User::getUserName, param.getUsername())
				.eq(ObjectUtil.isNotNull(param.getSex()), User::getSex, param.getSex()));
	}
}
